package org.wendu.wdoa.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.common.TaskNewEnum;
import org.wendu.wdoa.common.token.TokenUser;
import org.wendu.wdoa.common.token.TokenUtils;
import org.wendu.wdoa.dao.TaskDao;
import org.wendu.wdoa.dto.TaskBeanDto;
import org.wendu.wdoa.dto.TaskDto;
import org.wendu.wdoa.model.Task;
import org.wendu.wdoa.service.TaskService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class TaskServiceImpl implements TaskService {

    @Resource
    private TaskDao taskDao;


    @Override
    public void addNewTask(CurrentUser currentUser, TaskDto taskDto) {
        TokenUser tokenUser = TokenUtils.getTokenUser(currentUser.getUserId());
        taskDto.setTask_date(new Date());
        taskDto.setLeader_id(tokenUser.getUserId());
        taskDto.setTask_status(TaskNewEnum.no_commit.getCode());
        taskDao.addNewTask01(taskDto);
    }

    //修改状态为1
    @Override
    public void holdNewTask(String task_id) {
        taskDao.holdNewTask01(task_id);
    }

    @Override
    public List<Task> selectAllTask(CurrentUser currentUser) {
        TokenUser tokenUser = TokenUtils.getTokenUser(currentUser.getUserId());
        List<Task> list = taskDao.selectAllTesk01(tokenUser.getUserId());
        return list;
    }

    //查询状态为0
    @Override
    public List<Task> selectNoTask(CurrentUser currentUser) {
        TokenUser tokenUser = TokenUtils.getTokenUser(currentUser.getUserId());
        List<Task> list = taskDao.selectNoTask01(tokenUser.getUserId());
        return list;
    }

    @Override
    public void modifyTask(TaskDto taskDto) {
        taskDao.modifyTask01(taskDto);
    }

    @Override
    public void deleteTaskOne(String task_id) {
        taskDao.deleteTaskOne01(task_id);
    }

    @Override
    public void issueTask(TaskBeanDto taskBeanDto) {
        taskBeanDto.setTr_assign_date(new Date()); //设置下达任务时间
        taskDao.issueTask01(taskBeanDto);
    }
}
